package com.sysu.ooad.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.sysu.ooad.dao.TeacherDao;
import com.sysu.ooad.entity.Course;
import com.sysu.ooad.entity.Teacher;
import com.sysu.ooad.service.TeacherService;

@Component("teacherService")
public class TeacherServiceImpl implements TeacherService {
	private TeacherDao teacherDao;
	
	public TeacherDao getTeacherDao() {
		return teacherDao;
	}
	
	@Resource
	public void setTeacherDao(TeacherDao teacherDao) {
		this.teacherDao = teacherDao;
	}

	public Teacher login(String name, String password) {
		Teacher teacher = teacherDao.findByName(name);
		if(teacher != null && teacher.getPassword().equals(password)) {
			return teacher;
		}
		return null;
	}

	public List<Teacher> findAssistantsByCourse(Course c) {
		return teacherDao.findAssistantsByCourse(c);
	}

	public Teacher addAssistant(String name, String password, Course c) {
		Teacher assistant = new Teacher();
		assistant.setCourse(c);
		assistant.setName(name);
		assistant.setPassword(password);
		assistant.setPriviledge(Teacher.Priviledge.ASSISTANT);
		teacherDao.add(assistant);
		return assistant;
	}
	

}
